package net.itbull.alipay.controller;

import com.google.common.base.Strings;
import net.itbull.alipay.service.AlipayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@ResponseBody
@RequestMapping("/alipay")
public class AlipayController {
    /**
     * web端订单支付
     *
     * @param outTradeNo  订单编号（唯一）
     * @param totalAmount 订单价格
     * @param subject     商品名称
     */
    @Autowired
    AlipayService alipayService;
    @PostMapping("/pay")
    public String webPagePay(String outTradeNo,String subject,String totalAmount){
        return alipayService.webPagePay(subject, outTradeNo, totalAmount);
    }
    /**
     * 支付异步回调
     * @param request
     * @return
     */
    @PostMapping("/notifyUrl")
    public String notifyUrl(HttpServletRequest request){
       return alipayService.notifyUrl(request);
    }
    /**
     * 支付同步步回调
     * @param request
     * @return
     */
    @GetMapping("/returnUrl")
    public Map<String, String[]> returnUrl(HttpServletRequest request){
        return alipayService.returnUrl(request);
    }
    /**
     * 交易查询
     *
     * @param outTradeNo 订单编号
     * @param outTradeNo 交易号
     */
    @PostMapping("/tradeQuery")
    public String tradeQuery(String outTradeNo,String tradeNo){
       return alipayService.tradeQuery(outTradeNo, tradeNo);
    }

    /**
     * 退款接口
     *
     * @param outTradeNo   订单编号
     * @param outTradeNo   交易号
     * @param refundAmount 退款金额
     * @param outRequestNo 标识一次退款请求，同一笔交易多次退款需要保证唯一，如需部分退款，则此参数必传
     */
    @PostMapping("/refund")
    public String refund(String outTradeNo,String tradeNo,String refundAmount,String outRequestNo){
       return alipayService.refund(outTradeNo, tradeNo, refundAmount, outRequestNo);
    }

    /**
     * 退款查询接口
     * @param outTradeNo
     * @param tradeNo
     * @param outRequestNo
     * @return
     */
    @PostMapping("/refundQuery")
    public String refundQuery(String outTradeNo,String tradeNo,String outRequestNo){
        return alipayService.refundQuery(outTradeNo, tradeNo, outRequestNo);
    }
}
